// Tasks to build the Debian package
// In a separate build file (Groovy) to correctly configure the Deb task (user/group perms).
// Ref: https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/282
// 
// Note: 
// 1) we do not include the following files in the Deb, since these likely need to be generated by the maintainers of the
//     Linux distro
//    - /usr/share/doc/zaproxy/changelog.Debian.gz
//    - /usr/share/doc/zaproxy/copyright
// 2) We do NOT bundle the add-ons as part of the deb either. These should be deployed separately, for ease of deploy and maintenance.

tasks.register("distDebian", Deb) {
    group = "Distribution"
    description = "Bundles the Debian package."

    packageName = "zaproxy"
    packageDescription = "OWASP Zed Attack Proxy -an easy to use tool for finding vulnerabilities in web applications."
    packageGroup = "net"
    archiveVersion = provider { project.version }
    release = "1"
    maintainer = "Simon Bennetts <psiinon@gmail.com>"
    url = "https://github.com/zaproxy/zaproxy"
    priority = "extra"

    requires("java8-runtime")

    user = "0"

    def distFiles = tasks.named("distFiles")

    from(distFiles) {
        into("/usr/share/$packageName")
        exclude("zap.sh", "zap.bat", "plugin/*.zap")
        fileMode 0644
    }

    from(distFiles) {
        into("/usr/share/$packageName")
        include("zap.sh")
        fileMode 0755
    }

    def debSrcDir = file("src/main/debian/")

    from(new File(debSrcDir, "zap")) {
        into("/usr/bin")
        user "root"
        permissionGroup "root"
        fileMode 0755
    }

    from(new File(debSrcDir, "owasp-zap.desktop")) {
        into("/usr/share/applications")
        user "root"
        permissionGroup "root"
        fileMode 0644
    }

    from(new File(debSrcDir, "zapicon.png")) {
        into("/usr/share/icons/")
        user "root"
        permissionGroup "root"
        fileMode 0644
    }

    link("/usr/bin/owasp-zap", "/usr/bin/zap")
}
